package com.tina.mapper;

import com.tina.entity.TiRoleMenuRef;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tina.entity.vo.TiMenuVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 角色和菜单关联表 Mapper 接口
 * </p>
 *
 * @author PIGS
 * @since 2020-06-05
 */
@Repository
public interface TiRoleMenuRefMapper extends BaseMapper<TiRoleMenuRef> {
    /**
     * 通过角色id查询菜单权限
     *
     * @param roleId
     * @return
     */
    @Select("select ti_menu.menu_id as value,ti_menu.menu_name as name  from ti_menu left join ti_role_menu_ref on ti_role_menu_ref.menu_id=ti_menu.menu_id where role_id=#{roleId}")
    public List<TiMenuVo> queryRoleMenuRefListByRoleId(Long roleId);

    /**
     * 通过角色ID删除角色和菜单关联
     *
     * @param roleId 角色ID
     * @return 结果
     */
    @Delete("delete from ti_role_menu_ref where role_id=#{roleId}")
    public Integer deleteRoleMenuByRoleId(Long roleId);
}
